package ru.pachkun.home.russianpost.info;

import org.openqa.selenium.WebDriver;

import ru.pachkun.home.model.RTM;
import ru.pachkun.home.russianpost.info.logicinterface.InputRPOInterface;
import ru.pachkun.home.russianpost.info.logicinterface.MRPORegistrationHelperInterface;
import ru.pachkun.home.russianpost.info.logicinterface.ReadRTMInterface;

public class MRPORegistrationHealper extends DriverBasedHelper implements
		MRPORegistrationHelperInterface, ReadRTMInterface, InputRPOInterface {

	public MRPORegistrationHealper(ApplicationManager manager) {
		super(manager.getWebDriver());
	}

	@Override
	public void writeRTM(RTM rtm) {
		pages.mrpoRegistrationPage
			.setMailTypeID(rtm.getMailTypeID())
			.getBasicInformationRPOBlock()
			.setMailCtgID(rtm.getMailCtgID())
			.setOperTypeID(rtm.getOperTypeID())
			.setOperAttrID(rtm.getOperAttrID())
			.setDateOper(rtm.getDateOper())
			.setIndexOper(rtm.getIndexOper())
			.setBarCode(rtm.getBarCode());
		pages.mrpoRegistrationPage
			.getAdvancedInformationRPOBlock()
			.setWeight(rtm.getWeight())
			.setVal(rtm.getVal())
			.setPayment(rtm.getPayment())
			.setShipRate(rtm.getShipRate());
		pages.mrpoRegistrationPage
			.setAviaRate(rtm.getAviaRate())
			.getAdvancedInformationRPOBlock()
			.setInsuranceRate(rtm.getInsuranceRate())
			.setAdditionalRate(rtm.getAdditionalRate())
			.setAdValTax(rtm.getAdValTax())
			.setCountryToID(rtm.getCountryToID())
			.setIndexTo(rtm.getIndexTo())
			.setCountryFromID(rtm.getCountryFromID())
			.setIndexFrom(rtm.getIndexFrom());
		pages.mrpoRegistrationPage
			.setTransTypeID(rtm.getTransTypeID())
			.getAdvancedInformationRPOBlock()
			.setClientCtgID(rtm.getClientCtgID())
			.setMailRankID(rtm.getMailRankID())
			.setPostMarkID(rtm.getPostMarkID())
			.setPayTypeID(rtm.getPayTypeID());
	}

	@Override
	public Boolean isCheckRTM(RTM rtm) {
		return false;
	}

	@Override
	public void clickAddRPOButton() {
		pages.mrpoRegistrationPage.getButtonFormBlock().clickLinkAddRPOButton();
		pages.mrpoRegistrationPage.ensurePageLoaded();
	}

	@Override
	public void clickVerifyRPOButton() {
		pages.mrpoRegistrationPage.getButtonFormBlock().clickLinkVerifyRPOButton();
		pages.mrpoRegistrationPage.ensurePageLoaded();
	}

	@Override
	public void clickClearButton() {
		pages.mrpoRegistrationPage.getButtonFormBlock().clickLinkClearButton();
		pages.mrpoRegistrationPage.ensurePageLoaded();
	}
	
	/*Предупреждение на странице, есть блок p page error и кнопка добавить доступна
	 * */
	@Override
	public Boolean isWarningOnPage() {
		return pages.mrpoRegistrationPage.isErrorOnPage()
				&& pages.mrpoRegistrationPage.getButtonFormBlock()
						.isEnableAddRPOButton();
	}

	@Override
	public Boolean isWarningOnPage(String text) {
		return null;
	}

	/*
	 * Ошибка на странице, есть блок p page error и кнопка добавить <b>НЕ</b>
	 * доступна
	 */
	@Override
	public Boolean isErrorOnPage() {
		return pages.mrpoRegistrationPage.isErrorOnPage()
				&& !pages.mrpoRegistrationPage.getButtonFormBlock()
						.isEnableAddRPOButton();
	}

	@Override
	public Boolean isErrorOnPage(String text) {
		return null;
	}

	@Override
	public String getDateOper() {
		return pages.mrpoRegistrationPage.getBasicInformationRPOBlock()
				.getDateOper();
	}

}
